<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">修改晨检</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
      <div class="formcontent">
        <ul>
          <li>
            <span><em>*</em>晨检日期 </span>
            <div class="froms">
              <label>{{this.datatime|time}}</label>
  
            </div>
          </li>
          <li>
            <span><em>*</em>晨检结果</span>
            <div class="froms">
              <el-select v-model="value" placeholder="请选择" name="value" v-validate="'required'" :class="{'is-danger': errors.has('value')}">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </div>
          </li>
          <li>
            <span><em>*</em>姓名</span>
            <div class="froms">
              <label>{{this.enterprisePersonName}}</label>
            </div>
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>

<script>
  import {
    MorningRecordUpdate
  } from '../../api/api';
  import {
    MorningRecordDetail
  } from '../../api/api';
  
  export default {
    data() {
      return {
        options: [{
          value: '√',
          label: '正常'
        }, {
          value: '△',
          label: '发热'
        }, {
          value: '⊙',
          label: '腹泻'
        }, {
          value: '﹟',
          label: '皮肤溃疡'
        }, {
          value: '※',
          label: '其他传染病'
        }, {
          value: '不在岗',
          label: '不在岗位'
        }],
        value: this.$route.query.value,
        datatime: this.$route.query.datatime,
        enterprisePersonName: this.$route.query.name,
        enterprisePersonUnid: this.$route.query.enterprisePersonunid,
        Unid: this.$route.query.unid,
        listData: [],
        show: false, //默认隐藏
      };
    },
    methods: {
      submitForm: function() {
        debugger
        this.$validator.validateAll().then((result) => {
          if (result) {
            let varQueryData = {
              Name: this.enterprisePersonName,
              Unid: this.enterprisePersonUnid,
              //Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,//规范unid
            }
            let data = {
              MorningRecordDate: this.datatime,
              MorningRecordContent: this.value,
              Unid: this.Unid,
              EnterprisePerson: varQueryData,
            }
            let dataoption = {
              params: {
                Data: JSON.stringify(data),
                UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
              }
            }
            //调取接口
            MorningRecordUpdate(dataoption).then((res) => {
              if (res.success === true) {
                this.$message.success('保存成功');
                this.$router.go(-1);
              } else {
                this.$message.error(res.msg);
              }
            }).catch(function() {
              this.$message.error('网络异常。');
            })
          }else{
             this.$message.error('带*号为必填项，请确认填写格式正确');
          }
        })
  
  
      },
    },
    created() {
      this.getData();
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
  
</style>
